#include <iostream>
#include <cstdio>
#include <string>
#include <map>
using namespace std;
map<int, string> Map;
map<int, string>::iterator iter;
int n;
int main()
{
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        string s;
        cin >> s;
        if (s == "PUT")
        {
            string str;
            int num;
            cin >> str >> num;
            Map[num] = str;
        }
        if (s == "GET")
        {
            if (iter != Map.end() && !Map.empty())
            {
                iter = Map.begin();
                cout << iter->second << '\n';
                iter = Map.find(iter->first);
                Map.erase(iter);
            }
            else if (Map.empty())
                cout << "EMPTY QUEUE!\n";
        }
    }
    return 0;
}